package com.lx.chapter2.servlet;

import com.lx.chapter2.model.Customer;
import com.lx.chapter2.service.CustomerService;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 进入客户列表 界面
 *
 * @author 段誉
 * @create 2019-03-21 20:27
 */
@WebServlet("/customer")
public class CustomerServlet extends HttpServlet {
  private CustomerService customerService;

  /**
   * 初始化customerService
   * @throws ServletException
   */
  @Override
  public void init() throws ServletException {
    customerService = new CustomerService();
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
          IOException {
    List<Customer> customerList = customerService.getCustomerList();
    req.setAttribute("customerList", customerList);
    req.getRequestDispatcher("/WEB-INF/view/customer.jsp").forward(req, resp);
  }
}
